package com.jn.exam.question.service.impl;

import com.jn.exam.question.entity.Paper;
import com.jn.exam.question.entity.vo.PaperInfo;
import com.jn.exam.question.mapper.PaperMapper;
import com.jn.exam.question.service.PaperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 江南大学1033190417
 * @since 2022-02-06
 */
@Service
public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements PaperService {


    @Override
    @Transactional
    //新建试卷
    public boolean createNewPaper(String teacherId, Paper paper) {
        boolean newPaper = baseMapper.createNewPaper(paper);
        String paperId = paper.getId();
        String permission = "1";//赋予管理者权限
        boolean isAdd = baseMapper.insertPaperTeacherConnection(teacherId, paperId, permission);
        if (newPaper && isAdd) {
            return true;
        }
        return false;
    }

    @Override
    public List<PaperInfo> getRelatedPaper(String teacherId) {
        return baseMapper.getRelatedPaper(teacherId);
    }

    //删除试卷与老师的联系
    @Override
    public boolean removePaperTeacherConnection(String paperId) {
        return baseMapper.removePaperTeacherConnection(paperId);
    }

    //邀请某老师管理试卷
    @Override
    public boolean inviteOneTeacherForPaper(Map<String, Object> param) {
        return baseMapper.inviteOneTeacherForPaper(param);
    }

    //修改某老师关于某试卷权限
    @Override
    public boolean updatePaperPermissionForTeacher(Map<String, Object> param) {
        return baseMapper.updatePaperPermissionForTeacher(param);
    }

    //查询某老师与某试卷是否有联系
    @Override
    public List<Map<String, Object>> ifHasTeacherPaperConnection(Map<String, Object> param) {
        return baseMapper.ifHasTeacherPaperConnection(param);
    }

    @Override
    public boolean deleteTeacherFromPaper(Map<String, Object> param) {
        return baseMapper.deleteTeacherFromPaper(param);
    }

    //管理员查询各种状态的试卷
    @Override
    public List<PaperInfo> getAllStatusPaperInfo(String status) {
        return baseMapper.getAllStatusPaperInfo(status);
    }

    @Override
    public boolean savePaper(Paper paper) {
        return baseMapper.savePaper(paper);
    }

    @Override
    public Float getTotalScoreOfPaper(String paperId) {
        return baseMapper.getTotalScoreOfPaper(paperId);
    }
}
